package com.lwh.videopicplayer;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import java.lang.reflect.Method;

public class MyReceiver extends BroadcastReceiver {


    public static void setSystemProperty(String key, String value) {
        try {
            Class clz = Class.forName("android.os.SystemProperties");
            Method set = clz.getDeclaredMethod("set", String.class, String.class);
            set.invoke(clz, key, value);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static String getSystemProperty(String key, String defValue) {
        try {
            Class clz = Class.forName("android.os.SystemProperties");
            Method get = clz.getDeclaredMethod("get", String.class, String.class);
            return String.valueOf(get.invoke(clz, key, defValue));
        } catch (Exception e) {
            e.printStackTrace();
            return defValue;
        }
    }


    @Override
    public void onReceive(Context context, Intent intent) {
        if (PlayActivity.isRuning != true) {


            Intent i = new Intent(context, PlayActivity.class);
            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            context.startActivity(i);

            /*
            Settings.System.putInt(context.getContentResolver(), Settings.System.USER_ROTATION, 0);

            new Handler().postDelayed(new Runnable() {
                @Override
                public void run() {
                    String value = getSystemProperty("persist.user_rotation", "0");
                    Settings.System.putInt(context.getContentResolver(), Settings.System.USER_ROTATION, Integer.parseInt(value));
                    new Handler().postDelayed(new Runnable() {
                        @Override
                        public void run() {

                            Intent i = new Intent(context, MainActivity.class);
                            i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                            context.startActivity(i);
                        }
                    }, 4000);
                }
            }, 4000);
            */
        }
    }
}
